﻿using System.Collections.Generic;
using System.Diagnostics;

namespace Game.ResourceLocator
{
    public static class GameResourceLocator
    {
        static readonly Dictionary<string, IHasUrl> _Dictionary;
        
        static GameResourceLocator()
        {
            _Dictionary = new Dictionary<string, IHasUrl>();
        }
        
        public static void Register(IHasUrl url)
        {
            if (url.Url == null)
            {
                return;
            }
            
            if (!_Dictionary.ContainsKey(url.Url))
            {
                _Dictionary.Add(url.Url, url);
            }
        }
        
        public static IHasUrl Get(string url)
        {
            if (url == null)
            {
                Debug.Assert(false, url + "not found");
            }
            
            if (url.StartsWith("Rail"))
            {
                Debug.WriteLine(url);
            }
            
            if (!_Dictionary.ContainsKey(url))
            {
                Debug.Assert(false, url + "not found");
            }
            
            return _Dictionary[url];
        }
    }
}
